class Solution:
    def firstUniqChar(self, s: str) -> int:
        flag = dict()
        res = set(range(len(s)))
        for i in range(len(s)):
            if s[i] in flag:
                res.remove(i)
                if flag[s[i]] in res:
                    res.remove(flag[s[i]])
            flag[s[i]] = i
        return min(res) if len(res) > 0 else -1